Skip to content

Add Radarr sensor#7318

Merged
balloob merged 9 commits into
home-assistant:devfrom
tboyce021:tboyce021-radarr
Jun 5, 2017
Merged

Add Radarr sensor#7318
balloob merged 9 commits into
home-assistant:devfrom
tboyce021:tboyce021-radarr

Conversation

@tboyce021
Copy link
Copy Markdown
Contributor

@tboyce021 tboyce021 commented Apr 26, 2017

Description:

Adds a sensor component for Radarr.

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2567

Example entry for configuration.yaml (if applicable):

- platform: radarr
    api_key: !secret radarr_api_key
    host: 192.168.1.100
    monitored_conditions:
      - movies
      - upcoming
      - commands
      - diskspace
      - status
    days: 7

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@homeassistant
Copy link
Copy Markdown
Contributor

Hi @tboyce021,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

def to_unit(value, unit):
"""Convert bytes to give unit."""
return value / 1024**BYTE_SIZES.index(unit)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line at end of file

def to_key(data):
return '{} ({})'.format(data['title'], data['year'])

def to_unit(value, unit):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

date = data['inCinemas']
return date

def to_key(data):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

datetime.fromtimestamp(time.time() + day*offset, tz=zone)
)

def get_release_date(data):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected 2 blank lines, found 1

return datetime.date(
datetime.fromtimestamp(time.time() + day*offset, tz=zone)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line contains whitespace

attributes[to_key(movie)] = movie['hasFile']
elif self.type == 'status':
attributes = self.data

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line contains whitespace

elif self.type == 'wanted':
self.data = list(
filter(
lambda x: x['downloaded'] == False,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparison to False should be 'if cond is False:' or 'if not cond:'

if self.type == 'movies':
self.data = list(
filter(
lambda x: x['downloaded'] == True,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comparison to True should be 'if cond is True:' or 'if cond:'

@tboyce021
Copy link
Copy Markdown
Contributor Author

NOTE: I have not tested this thoroughly yet (haven't tested upcoming at all). I just copied sonarr.py and made some adjustments so it would work with Radarr. Since not all of the data is the same, I just kind of picked something that looked useful.

elif self.type == 'wanted':
self.data = list(
filter(
lambda x: not x['downloaded'],
Copy link
Copy Markdown
Contributor Author

@tboyce021 tboyce021 Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't really sure what to do here. Radarr doesn't have a "wanted" API, so I just filtered movies based on whether they were downloaded or not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Radarr doesn't support it, remove it.

import homeassistant.helpers.config_validation as cv
from homeassistant.const import (CONF_API_KEY, CONF_HOST, CONF_PORT)
from homeassistant.const import CONF_MONITORED_CONDITIONS
from homeassistant.const import CONF_SSL
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge all from homeassistant.const lines.

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_MONITORED_CONDITIONS, default=[]):
vol.All(cv.ensure_list, [vol.In(list(SENSOR_TYPES.keys()))]),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.keys() is the default. Needs to be removed for pylint 1.7.1.

self.port = conf.get(CONF_PORT)
self.urlbase = conf.get(CONF_URLBASE)
if self.urlbase:
self.urlbase = "%s/" % self.urlbase.strip('/')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use string formatting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it doesn't add much value.

elif self.type == 'wanted':
self.data = list(
filter(
lambda x: not x['downloaded'],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Radarr doesn't support it, remove it.

DEFAULT_URLBASE = ''
DEFAULT_DAYS = '1'
DEFAULT_UNIT = 'GB'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add SCAN_INTERVAL. I think that's enough if this sensor is updated every 5 or 10 min per default.

ENDPOINTS[self.type].format(
self.ssl, self.host, self.port,
self.urlbase, self.apikey, start, end),
timeout=5)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If would be easier to read if X-Api-Key is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I have no idea how to do this.. I wrote very little of this myself. It's almost all copied from the existing Sonarr sensor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
elif self.type == 'movies':
for movie in self.data:
attributes[to_key(movie)] = movie['downloaded']
Copy link
Copy Markdown
Contributor Author

@tboyce021 tboyce021 May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also changed the attribute value to 'downloaded' instead of 'hasFile'. I honestly don't know which one is preferred. For me, they're always the same.

@tboyce021
Copy link
Copy Markdown
Contributor Author

I'll work on getting tests next but it'll take me a day or two to get set up for that.

@homeassistant
Copy link
Copy Markdown
Contributor

Hello @tboyce021,

When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es).

The commits that are missing a linked GitHub account are the following:

Unfortunately, we are unable to accept this pull request until this situation is corrected.

Here are your options:

  1. If you had an email address set for the commit that simply wasn't linked to your GitHub account you can link that email now and it will retroactively apply to your commits. The simplest way to do this is to click the link to one of the above commits and look for a blue question mark in a blue circle in the top left. Hovering over that bubble will show you what email address you used. Clicking on that button will take you to your email address settings on GitHub. Just add the email address on that page and you're all set. GitHub has more information about this option in their help center.

  2. If you didn't use an email address at all, it was an invalid email, or it's one you can't link to your GitHub, you will need to change the authorship information of the commit and your global Git settings so this doesn't happen again going forward. GitHub provides some great instructions on how to change your authorship information in their help center.

    • If you only made a single commit you should be able to run
      git commit --amend --author="Author Name <email@address.com>"
      
      (substituting Author Name and email@address.com for your actual information) to set the authorship information.
    • If you made more than one commit and the commit with the missing authorship information is not the most recent one you have two options:
      1. You can re-create all commits missing authorship information. This is going to be the easiest solution for developers that aren't extremely confident in their Git and command line skills.
      2. You can use this script that GitHub provides to rewrite history. Please note: this should be used only if you are very confident in your abilities and understand its impacts.
    • Whichever method you choose, I will come by to re-check the pull request once you push the fixes to this branch.

We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community.

Thanks, I look forward to checking this PR again soon! ❤️

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no newline at end of file

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (89 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (89 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (89 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (91 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (340 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (94 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (94 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (163 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local variable 'today' is assigned to but never used

Comment thread tests/components/sensor/test_radarr.py Outdated
self.assertEqual('Radarr Upcoming', device.name)
self.assertEqual(
'2017-01-27T00:00:00Z',
device.device_state_attributes["Resident Evil: The Final Chapter (2017)"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (89 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
self.assertEqual('Radarr Upcoming', device.name)
self.assertEqual(
'2017-01-27T00:00:00Z',
device.device_state_attributes["Resident Evil: The Final Chapter (2017)"]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (89 > 79 characters)

Comment thread tests/components/sensor/test_radarr.py Outdated
{
"coverType": "banner",
"url": "/radarr/MediaCover/1/banner.jpg"
+ "?lastWrite=636200219340000000"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line unaligned for hanging indent

Comment thread tests/components/sensor/test_radarr.py Outdated
{
"coverType": "banner",
"url": "/radarr/MediaCover/12/banner.jpg"
+ "?lastWrite=636208663600000000"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line unaligned for hanging indent

Comment thread tests/components/sensor/test_radarr.py Outdated
"""The tests for the radarr platform."""
import unittest
import time
from datetime import datetime
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'datetime.datetime' imported but unused

Comment thread tests/components/sensor/test_radarr.py Outdated
@@ -0,0 +1,451 @@
"""The tests for the radarr platform."""
import unittest
import time
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'time' imported but unused

Comment thread tests/components/sensor/test_radarr.py Outdated
{
"coverType": "banner",
"url": "/radarr/MediaCover/12/banner.jpg"
+ "?lastWrite=636208663600000000"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuation line unaligned for hanging indent

@tboyce021
Copy link
Copy Markdown
Contributor Author

The tests were also mostly just copied from Sonarr, but with the data and stuff changed for Radarr. I'll work on getting the documentation up tomorrow.

@balloob balloob merged commit 2e27c0d into home-assistant:dev Jun 5, 2017
@jesserockz jesserockz mentioned this pull request Jun 5, 2017
6 tasks
@fabaff fabaff mentioned this pull request Jun 5, 2017
1 task
@tboyce021 tboyce021 deleted the tboyce021-radarr branch June 6, 2017 16:09
@balloob balloob mentioned this pull request Jun 16, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Sep 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants